home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / rex.lha / rex / m2c / DefTable.c < prev    next >
C/C++ Source or Header  |  1992-08-18  |  4KB  |  184 lines

  1. #include "SYSTEM_.h"
  2.  
  3. #ifndef DEFINITION_DynArray
  4. #include "DynArray.h"
  5. #endif
  6.  
  7. #ifndef DEFINITION_Idents
  8. #include "Idents.h"
  9. #endif
  10.  
  11. #ifndef DEFINITION_Tree
  12. #include "Tree.h"
  13. #endif
  14.  
  15. #ifndef DEFINITION_DefTable
  16. #include "DefTable.h"
  17. #endif
  18.  
  19. DefTable_DefRange DefTable_DefCount;
  20.  
  21. #define InitialDefTableSize    32
  22. typedef struct S_1 {
  23.     Idents_tIdent Symbol;
  24.     DefTable_tKind Kind;
  25.     union {
  26.         struct {
  27.             Tree_tTree Tree;
  28.             SHORTCARD LeafCount;
  29.             BOOLEAN IsConstantRE;
  30.         } V_1;
  31.         struct {
  32.             SHORTCARD Number;
  33.         } V_2;
  34.     } U_1;
  35. } DefType;
  36. typedef struct S_2 {
  37.     DefType A[100000 + 1];
  38. } DefTable;
  39. static DefTable *DefTablePtr;
  40. static LONGINT DefTableSize;
  41.  
  42.  
  43. void DefTable_MakeIdentDef
  44. # ifdef __STDC__
  45. (Idents_tIdent pSymbol, Tree_tTree pTree, SHORTCARD pLeafCount, BOOLEAN pIsConstantRE)
  46. # else
  47. (pSymbol, pTree, pLeafCount, pIsConstantRE)
  48. Idents_tIdent pSymbol;
  49. Tree_tTree pTree;
  50. SHORTCARD pLeafCount;
  51. BOOLEAN pIsConstantRE;
  52. # endif
  53. {
  54.   INC(DefTable_DefCount);
  55.   if (DefTable_DefCount == DefTableSize) {
  56.     DynArray_ExtendArray((ADDRESS *)&DefTablePtr, &DefTableSize, (LONGINT)sizeof(DefType));
  57.   }
  58.   {
  59.     register DefType *W_1 = &DefTablePtr->A[DefTable_DefCount];
  60.  
  61.     W_1->Symbol = pSymbol;
  62.     W_1->Kind = DefTable_Ident;
  63.     W_1->U_1.V_1.Tree = pTree;
  64.     W_1->U_1.V_1.LeafCount = pLeafCount;
  65.     W_1->U_1.V_1.IsConstantRE = pIsConstantRE;
  66.   }
  67. }
  68.  
  69. void DefTable_MakeStartDef
  70. # ifdef __STDC__
  71. (Idents_tIdent pSymbol, SHORTCARD pNumber)
  72. # else
  73. (pSymbol, pNumber)
  74. Idents_tIdent pSymbol;
  75. SHORTCARD pNumber;
  76. # endif
  77. {
  78.   INC(DefTable_DefCount);
  79.   if (DefTable_DefCount == DefTableSize) {
  80.     DynArray_ExtendArray((ADDRESS *)&DefTablePtr, &DefTableSize, (LONGINT)sizeof(DefType));
  81.   }
  82.   {
  83.     register DefType *W_2 = &DefTablePtr->A[DefTable_DefCount];
  84.  
  85.     W_2->Symbol = pSymbol;
  86.     W_2->Kind = DefTable_Start;
  87.     W_2->U_1.V_2.Number = pNumber;
  88.   }
  89. }
  90.  
  91. DefTable_DefRange DefTable_GetDef
  92. # ifdef __STDC__
  93. (Idents_tIdent pSymbol)
  94. # else
  95. (pSymbol)
  96. Idents_tIdent pSymbol;
  97. # endif
  98. {
  99.   DefTable_DefRange Def;
  100.  
  101.   {
  102.     LONGINT B_1 = 1, B_2 = DefTable_DefCount;
  103.  
  104.     if (B_1 <= B_2)
  105.       for (Def = B_1;; Def += 1) {
  106.         if (DefTablePtr->A[Def].Symbol == pSymbol) {
  107.           return Def;
  108.         }
  109.         if (Def >= B_2) break;
  110.       }
  111.   }
  112.   return DefTable_NoDef;
  113. }
  114.  
  115. DefTable_tKind DefTable_GetKind
  116. # ifdef __STDC__
  117. (DefTable_DefRange pDef)
  118. # else
  119. (pDef)
  120. DefTable_DefRange pDef;
  121. # endif
  122. {
  123.   return DefTablePtr->A[pDef].Kind;
  124. }
  125.  
  126. void DefTable_GetIdentDef
  127. # ifdef __STDC__
  128. (DefTable_DefRange pDef, Idents_tIdent *pSymbol, Tree_tTree *pTree, SHORTCARD *pLeafCount, BOOLEAN *pIsConstantRE)
  129. # else
  130. (pDef, pSymbol, pTree, pLeafCount, pIsConstantRE)
  131. DefTable_DefRange pDef;
  132. Idents_tIdent *pSymbol;
  133. Tree_tTree *pTree;
  134. SHORTCARD *pLeafCount;
  135. BOOLEAN *pIsConstantRE;
  136. # endif
  137. {
  138.   {
  139.     register DefType *W_3 = &DefTablePtr->A[pDef];
  140.  
  141.     *pSymbol = W_3->Symbol;
  142.     *pTree = W_3->U_1.V_1.Tree;
  143.     *pLeafCount = W_3->U_1.V_1.LeafCount;
  144.     *pIsConstantRE = W_3->U_1.V_1.IsConstantRE;
  145.   }
  146. }
  147.  
  148. void DefTable_GetStartDef
  149. # ifdef __STDC__
  150. (DefTable_DefRange pDef, Idents_tIdent *pSymbol, SHORTCARD *pNumber)
  151. # else
  152. (pDef, pSymbol, pNumber)
  153. DefTable_DefRange pDef;
  154. Idents_tIdent *pSymbol;
  155. SHORTCARD *pNumber;
  156. # endif
  157. {
  158.   {
  159.     register DefType *W_4 = &DefTablePtr->A[pDef];
  160.  
  161.     *pSymbol = W_4->Symbol;
  162.     *pNumber = W_4->U_1.V_2.Number;
  163.   }
  164. }
  165.  
  166. void BEGIN_DefTable()
  167. {
  168.   static BOOLEAN has_been_called = FALSE;
  169.  
  170.   if (!has_been_called) {
  171.     has_been_called = TRUE;
  172.  
  173.     BEGIN_Idents();
  174.     BEGIN_Tree();
  175.     BEGIN_DynArray();
  176.     BEGIN_Idents();
  177.     BEGIN_Tree();
  178.  
  179.     DefTableSize = InitialDefTableSize;
  180.     DynArray_MakeArray((ADDRESS *)&DefTablePtr, &DefTableSize, (LONGINT)sizeof(DefType));
  181.     DefTable_DefCount = 0;
  182.   }
  183. }
  184.